import lejos.nxt.Button;
import lejos.nxt.Sound;
import lejos.subsumption.Behavior;

public class JukeBox extends Thread implements Behavior {

	private final short[] worms = { 440, 21, 494, 21, 554, 43, 659, 43, 659,
			43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21, 554, 21, 494, 64,
			440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370, 85, 494, 32, 440,
			11, 494, 21, 554, 21, 494, 43, 440, 21, 494, 21, 554, 43, 659, 43,
			659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21, 554, 21, 494,
			64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370, 85, 494, 32,
			440, 11, 494, 21, 554, 21, 494, 43, 523, 21, 587, 21, 659, 43, 784,
			43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11, 587, 21, 659, 21,
			587, 64, 523, 21, 587, 32, 523, 11, 587, 21, 659, 21, 440, 85, 587,
			32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21, 587, 21, 659, 43,
			784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11, 587, 21, 659,
			21, 698, 64, 659, 21, 587, 32, 523, 11, 587, 21, 659, 21, 440, 85,
			587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21, 494, 21, 440,
			171, 659, 171, 880, 171, 220, 21, 0, 1517, 277, 21, 0, 21, 277, 21,
			0, 21, 277, 21, 0, 21, 294, 21, 330, 21, 294, 21, 277, 11, 247, 43,
			0, 11, 294, 21, 330, 21, 294, 21, 277, 21, 330, 21, 0, 21, 330, 21,
			0, 21, 330, 21, 0, 21, 370, 21, 415, 21, 440, 28, 0, 14, 440, 28,
			0, 14, 440, 28, 0, 14, 523, 43, 659, 85, 440, 171, 494, 43, 440,
			21, 494, 21, 554, 171, 0, 128, 440, 21, 494, 21, 554, 43, 659, 43,
			659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21, 554, 21, 494,
			64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370, 85, 494, 32,
			440, 11, 494, 21, 554, 21, 494, 43, 440, 21, 494, 21, 554, 43, 659,
			43, 659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21, 554, 21,
			494, 64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370, 85, 494,
			32, 440, 11, 494, 21, 554, 21, 494, 43, 523, 21, 587, 21, 659, 43,
			784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11, 587, 21, 659,
			21, 587, 64, 523, 21, 587, 32, 523, 11, 587, 21, 659, 21, 440, 85,
			587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21, 587, 21, 659,
			43, 784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11, 587, 21,
			659, 21, 698, 64, 659, 21, 587, 32, 523, 11, 587, 21, 659, 21, 440,
			85, 587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21, 494, 21,
			440, 171, 659, 171, 880, 171, 220, 21, 0, 1517, 277, 21, 0, 21,
			277, 21, 0, 21, 277, 21, 0, 21, 294, 21, 330, 21, 294, 21, 277, 11,
			247, 43, 0, 11, 294, 21, 330, 21, 294, 21, 277, 21, 330, 21, 0, 21,
			330, 21, 0, 21, 330, 21, 0, 21, 370, 21, 415, 21, 440, 28, 0, 14,
			440, 28, 0, 14, 440, 28, 0, 14, 523, 43, 659, 85, 440, 171, 494,
			43, 440, 21, 494, 21, 554, 171, 0, 128, 440, 21, 494, 21, 554, 43,
			659, 43, 659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21, 554,
			21, 494, 64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370, 85,
			494, 32, 440, 11, 494, 21, 554, 21, 494, 43, 440, 21, 494, 21, 554,
			43, 659, 43, 659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494, 21,
			554, 21, 494, 64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21, 370,
			85, 494, 32, 440, 11, 494, 21, 554, 21, 494, 43, 523, 21, 587, 21,
			659, 43, 784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11, 587,
			21, 659, 21, 587, 64, 523, 21, 587, 32, 523, 11, 587, 21, 659, 21,
			440, 85, 587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21, 587,
			21, 659, 43, 784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523, 11,
			587, 21, 659, 21, 698, 64, 659, 21, 587, 32, 523, 11, 587, 21, 659,
			21, 440, 85, 587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523, 21,
			494, 21, 440, 171, 659, 171, 880, 171, 220, 21, 0, 1517, 277, 21,
			0, 21, 277, 21, 0, 21, 277, 21, 0, 21, 294, 21, 330, 21, 294, 21,
			277, 11, 247, 43, 0, 11, 294, 21, 330, 21, 294, 21, 277, 21, 330,
			21, 0, 21, 330, 21, 0, 21, 330, 21, 0, 21, 370, 21, 415, 21, 440,
			28, 0, 14, 440, 28, 0, 14, 440, 28, 0, 14, 523, 43, 659, 85, 440,
			171, 494, 43, 440, 21, 494, 21, 554, 171, 0, 128, 440, 21, 494, 21,
			554, 43, 659, 43, 659, 43, 587, 21, 554, 21, 494, 32, 440, 11, 494,
			21, 554, 21, 494, 64, 440, 21, 494, 32, 440, 11, 494, 21, 554, 21,
			370, 85, 494, 32, 440, 11, 494, 21, 554, 21, 494, 43, 440, 21, 494,
			21, 554, 43, 659, 43, 659, 43, 587, 21, 554, 21, 494, 32, 440, 11,
			494, 21, 554, 21, 494, 64, 440, 21, 494, 32, 440, 11, 494, 21, 554,
			21, 370, 85, 494, 32, 440, 11, 494, 21, 554, 21, 494, 43, 523, 21,
			587, 21, 659, 43, 784, 43, 784, 43, 698, 21, 659, 21, 587, 32, 523,
			11, 587, 21, 659, 21, 587, 64, 523, 21, 587, 32, 523, 11, 587, 21,
			659, 21, 440, 85, 587, 32, 523, 11, 587, 21, 659, 21, 587, 43, 523,
			21, 587, 21, 659, 43, 784, 43, 784, 43, 698, 21, 659, 21, 587, 32,
			523, 11, 587, 21, 659, 21, 698, 64, 659, 21, 587, 32, 523, 11, 587,
			21, 659, 21, 440, 85, 587, 32, 523, 11, 587, 21, 659, 21, 587, 43,
			523, 21, 494, 21, 440, 171, 659, 171, 880, 171, 220, 21, };

	public void action() {
		JukeBox juke = new JukeBox();
		juke.start();
	}

	public void suppress() {
		// TODO Auto-generated method stub

	}

	public boolean takeControl() {
		return true;
	}

	public void play_worms() {
		for (int i = 0; i < worms.length; i += 2) {
			final short w = worms[i + 1];
			Sound.playTone(worms[i], w);
			try {
				Thread.sleep(w * 10);
			} catch (InterruptedException e) {
			}
		}
	}

	public void run() {
		play_worms();
	}

}
